package com.wind.sqlite.tools;


import com.wind.httpProxyServer.manager.WhiteListManager;
import com.wind.sqlite.common.utils.SpringContextUtils;
import com.wind.sqlite.entity.ColumnWhiteListTEntity;
import com.wind.sqlite.entity.WhiteListTEntity;
import com.wind.sqlite.service.ColumnWhiteListTService;
import com.wind.sqlite.service.WhiteListTService;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

public class WhilteTools {
   public  static void setWhilteToCache(){

       WhiteListTService whiteListTService = SpringContextUtils.getBean("whiteListTService", WhiteListTService.class);
       ColumnWhiteListTService columnWhiteListTService = SpringContextUtils.getBean("columnWhiteListTService", ColumnWhiteListTService.class);
       List<WhiteListTEntity> whiteList = whiteListTService.list();
       List<ColumnWhiteListTEntity> columnWhiteList = columnWhiteListTService.list();
       WhiteListManager.whites = whiteList.stream().collect(Collectors.groupingBy(WhiteListTEntity::getProcessId,
               Collectors.mapping(WhiteListTEntity::getIp, Collectors.toList())));
       WhiteListManager.columnWhites = new CopyOnWriteArrayList<>(columnWhiteList.stream().map(ColumnWhiteListTEntity::getIp).collect(Collectors.toList()));
       System.out.println("columnWhites:"+ WhiteListManager.columnWhites.size());


   }
}


